public class Test {
    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        for(int i = 0;i < s.length();i++) {
            char ch = s.charAt(i);

            if(ch == '(' || ch == '{' || ch == '[') {
                stack.push(ch);
            }else {
                //ch = 右括号
                if(stack.peek() == null) {
                    return false;
                }

                if(stack.pop() != ch) {
                    return false;
                }

            }
            return true;
        }
        public boolean isValid(String s) {
            Stack<Character> stack = new Stack<>();
            for(int i = 0;i < s.length();i++) {
                char ch = s.charAt(i);

                if(ch == '(' || ch == '{' || ch == '[') {
                    stack.push(ch);
                }else {
                    //ch = 右括号
                    if(stack.peek() == null) {
                        return false;
                    }

                    if(stack.pop() != ch) {
                        return false;
                    }

                }
                return true;
            }
            public boolean isValid(String s) {
                Stack<Character> stack = new Stack<>();
                for(int i = 0;i < s.length();i++) {
                    char ch = s.charAt(i);

                    if(ch == '(' || ch == '{' || ch == '[') {
                        stack.push(ch);
                    }else {
                        //ch = 右括号
                        if(stack.peek() == null) {
                            return false;
                        }

                        if(stack.pop() != ch) {
                            return false;
                        }

                    }
                    return true;
                }
}
